package com.kxxnzstdsw.router

import com.kxxnzstdsw.exception.can.ValidatorException
import com.kxxnzstdsw.service.SystemService
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import org.koin.ktor.ext.inject

fun Route.system() {
  val systemService by inject<SystemService>()
  route("/system") {
    get("/captcha/{key}") {
      val with = call.parameters["with"]?.toInt() ?: 200
      val height = call.parameters["height"]?.toInt() ?: 100
      val key = call.parameters["key"] ?: throw ValidatorException("请确保key存在")
      call.respondOutputStream(ContentType.Image.GIF) {
        systemService.getCaptcha(key, with, height, this)
      }
    }
  }
}
